import { Subscription } from './../internal/Subscription';
import { GlobalInstanceFinder } from './GlobalInstanceFinder';
import { LifeCycleReactive } from './LifeCycleReactive';
import { _decorator, Component, Color } from 'cc';
import { applyMixins } from '../../utils/applyMixins';
import { LogWithTag, LogWithTagInnerData } from './LogWithTag';
import { ReactiveProperty } from './ReactiveProperty';
const { ccclass } = _decorator;

@ccclass('BaseView')
export class BaseView extends Component implements LifeCycleReactive, LogWithTag, GlobalInstanceFinder {

    willBind() { }

    onLoadView() { }

    onDestroyView() { }

    onLoad() {
        this.componentRegister();
        this.logInit();
        this.willBind();
        this.bind();
        this.onLoadView();
    }

    onDestroy() {
        this.onDestroyView();
        this.unbind();
    }

    // Implement delegates

    // LifeCycleReactive
    binded = ReactiveProperty.Create(false);
    bind() { }
    unbind() { }
    manualBind(list: (Subscription | (() => Subscription))[]): void { }
    _mainSubscription?: Subscription;
    getMainSubscription(): Subscription { return null; }
    _extraManagedSubscriptions?: Record<string, Subscription> = {};
    getExtraManagedSubscriptions(): Record<string, Subscription> { return null; }
    resetSubscriptions(key: string, genSubscription: () => Subscription): void { };


    // LogWithTag delegate
    _lwt = {} as LogWithTagInnerData;
    get logEnable(): boolean { return }
    get logColorOverride(): Color { return }
    logInit() { }
    debug(...param: any[]) { }
    log(...param: any[]) { }
    warn(...param: any[]) { }
    error(...param: any[]) { }
    // time(label: string) { }
    // timeLog(key: string, ...param) { }

    // GlobalInstanceFinder delegate
    componentRegister() { }
    systemRegister(...param: any[]) { }
}

applyMixins(BaseView, [LifeCycleReactive, LogWithTag, GlobalInstanceFinder]);

